<template>
  <view>
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
      <swiper-item v-for="(item,i) in swiperList" :key="i">
        <navigator class="swiper-item" :url="'/subpackage/goods_detail/goods_detail?goods_id='+item.goods_id">
          <image :src="item.image_src" mode=""></image>
        </navigator>
      </swiper-item>
    </swiper>

    <view class="nav-list">
      <view class="nav-item" v-for="(item,index) in navList" :key="index" @click="navClickToCate(item)">
        <image class="nav-item-img"  :src="item.image_src" mode=""></image>
      </view>
    </view>
    
    <view class="floorList">
      <view class="floor-item" v-for="(item,index) in floorList" :key="index">
        <image class="floor-item-img" :src="item.floor_title.image_src" mode="" ></image>
        <view class="floor-item-box">
          <view class="floor-img-box">
            <image :src="item.product_list[0].image_src" mode="widthFix" :style="{width:item.product_list[0].image_width+'rpx'}" ></image>
          </view>
          <view class="right-box">
            <navigator class="right-box-item" v-for="(item2,index2) in item.product_list.slice(1)" :key="index2" :url="item2.navigator_url">
              <image :src="item2.image_src" mode="widthFix" :style="{width:item2.image_width+'rpx'}"></image>
            </navigator>
          </view>
        </view>
      </view>
    </view>
    
  </view>
</template>

<script>
  import tabbarBadge from '../../mixins/tabbar-badge';
  export default {
    mixins:[tabbarBadge],
    data() {
      return {
        swiperList: [],
        navList: [],
        floorList:[]
      };
    },
    onLoad() {
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods: {
      async getSwiperList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/swiperdata')
        if (res.meta.status != 200) {
          return uni.$showMsg()
        }
        this.swiperList = res.message
      },
      async getNavList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/catitems')
        if (res.meta.status != 200) {
          return uni.$showMsg()
        }
        this.navList = res.message
      },
      navClickToCate(item){
          if(item.name === '分类'){
            uni.switchTab({
              url:'/pages/cate/cate'
            })
          }
      },
      async getFloorList() {
        const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')
        if (res.meta.status != 200) {
          return uni.$showMsg()
        }
        res.message.forEach((item)=>{
          item.product_list.forEach(product => {
            product.navigator_url = '/subpackage/goods_list/goods_list?'+ product.navigator_url.split('?')[1]
          })
        })
        this.floorList = res.message
      }
    }

  }
</script>

<style lang="scss">
  swiper {
    height: 330rpx;

    .swiper-item,
    image {
      width: 100%;
      height: 100%;
    }
  }

  .nav-list {
    display: flex;
    justify-content: space-around;
    margin: 15px 0;
    height: 140rpx;
    .nav-item {
      width: 20%;
      height: 100%;
      image{
        width: 100%;
        height: 100%;
      }
    }
    // .nav-item {
    //   width: 20%;
    //   height: 140rpx;
    //   image{
    //     width: 100%;
    //     height: 100%;
    //   }
    // }
  }
  .floorList {
    .floor-item{
      .floor-item-img{
        width: 100%;
        height: 60rpx;
      }
      .floor-item-box{
        display: flex;
         margin-left: 15rpx;
        .right-box{
          display: flex;
          justify-content: space-around;
          flex-wrap: wrap;
        }
      }

    }
  }
</style>